﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;
using System.Windows.Input;

namespace KeyboardImageViewer
{
    public class MappingAdder
    {
        private SQLiteCommand insertMapping;
        private SQLiteParameter inputCodeParam;
        private SQLiteParameter inputTypeParam;
        private SQLiteParameter actionCodeParam;

        public MappingAdder(SQLiteConnection connection)
        {
            this.insertMapping = new SQLiteCommand("INSERT INTO inputMapping (inputCode, inputType, actionCode) VALUES (?, ?, ?)", connection);
            this.inputCodeParam = insertMapping.Parameters.Add("inputCode", DbType.Int32);
            this.inputTypeParam = insertMapping.Parameters.Add("inputType", DbType.Int32);
            this.actionCodeParam = insertMapping.Parameters.Add("actionCode", DbType.Int32);
        }

        public void AddMapping(Key key, UserAction action)
        {
            this.AddMapping((int)key, InputType.Keyboard, action);
        }

        public void AddMapping(MouseButton mouseButton, UserAction action)
        {
            this.AddMapping((int)mouseButton, InputType.Mouse, action);
        }

        public void AddMapping(MouseWheelAction wheelAction, UserAction action)
        {
            this.AddMapping((int)wheelAction, InputType.MouseWheel, action);
        }

        public void AddMapping(int inputCode, InputType inputType, UserAction action)
        {
            this.inputCodeParam.Value = inputCode;
            this.inputTypeParam.Value = (int)inputType;
            this.actionCodeParam.Value = (int)action;

            this.insertMapping.ExecuteNonQuery();
        }
    }
}
